import axios from 'axios';

//axios.defaults.baseURL = 'http://192.168.71.29:8600/sap/opu/odata/sap/';
axios.defaults.baseURL = 'http://10.118.80.40:9403';//访问后台的服务器域名+端口
axios.defaults.withCredentials = true;
axios.defaults.timeout = 8000;       //测试暂时修改成8000
axios.defaults.headers['Access-Control-Allow-Origin'] = '*';
axios.defaults.headers['X-Requested-With'] = 'X';



// axios拦截器
axios.interceptors.request.use(config => {

    config.headers.common['X-Requested-With'] = 'X';
    config.headers.common['Access-Control-Allow-Origin'] = '*';
    config.headers.post = {};
    config.headers.put = {};
    config.headers.patch = {};
    return config
})
axios.interceptors.response.use(response => {
     // 在这里你可以判断后台返回数据携带的请求码
    if (response.status === 200 || response.status === 201 || response.status === 204) {
      return response.data.data || response.data
    }else{
      // 非200请求抱错
      throw Error(response.data.msg || '服务异常');
    }
})
export default axios;